﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<form class="layui-form" lay-filter="dictype-form" style="padding: 15px 0 0 0;">
    <input type="hidden" name="Id" value="0" />

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">名称</label>
        <div class="layui-input-block">
            <input type="text" name="funname" lay-verify="required" placeholder="请输入字典名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">代码</label>
        <div class="layui-input-block">
            <input type="text" name="funcode" required lay-verify="required" placeholder="请输入代码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标样式</label>
        <div class="layui-input-block">
            <input type="text" name="funicon" placeholder="可以填写css样式" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" id="funseq" name="funseq" placeholder="请输入排序"
                   autocomplete="off" class="layui-input" min="0" max="99" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            备注
        </label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-hide" lay-submit lay-filter="fun-submit" id="fun-submit">提交</button>
        </div>
    </div>
</form>


@section scripts{

    <script type="text/javascript">
        layui.use(['lscom', 'form'], function () {
            var $ = layui.$;
            var lscom = layui.lscom;
            var form = layui.form;

            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.iframeAuto(index);

            window.submitForm = function () {
                $("#fun-submit").click();
            }

            form.on('submit(fun-submit)', function (data) {
                var field = data.field;
                var waitIndex = parent.layer.load(2);
                lscom.ajax({
                    url: "/Systems/Menu/SaveFunction",
                    data: JSON.stringify(field),
                    lsHandleError: false
                }).done(function (data) {
                    if (data.code == 0) {
                        data.index = index;
                        let parentWindow = parent.selectedWindow().window;
                        parentWindow.saveCallback(data);
                    }
                }).fail(function (message) {
                    lscom.notify.error(message);
                }).always(function () {
                    parent.layer.close(waitIndex);
                });

                return false;
            });
        });
    </script>
    <script>

        layui.use(['form', 'okUtils', 'okLayer'], function () {
            $ = layui.jquery;
            var form = layui.form,
                okLayer = layui.okLayer, okUtils = layui.okUtils;
            okLoading.close();
            //自定义验证规则
            form.verify({
                funname: function (value) {
                    if (lscom.strlength(value) > 10) {
                        return '超过10个字符限制';
                    }
                }
            });

            //监听提交
            form.on('submit(add)',
                function (data) {
                    lscom.saveformdata("/Systems/Menu/SaveFunction", $(data.form).serialize(), okUtils, okLayer);

                    return false;
                });

        });</script>
}

